#!/usr/bin/perl #****************************************************************************** # # hana.cgi - Access Analyzer # #Version :2.14 #modified :2001/10/10 #Copyright :The Room #E-Mail :dream@lib.net #URL :http://dream.lib.net/room/ # #****************************************************************************** #1行目のperlのディレクトリ指定は、サーバによって異なります。 #詳しくは、管理者にお聞きください。 #****************************************************************************** #データ受け取り require './hana_set.cgi'; require $lib_jcode; &read_setting; $cl = $ENV{"CONTENT_LENGTH"}; if( $cl > 0 ){ read(STDIN, $qs, $cl ); }else{ $qs = $ENV{"QUERY_STRING"}; } if ($qs =~ /^ref=/){ $contents[0]=$qs; }else{ @contents = split(/&/,$qs,5); } foreach $i (0 .. $#contents) { local($key,$text)= split(/=/,$contents[$i],2); if ($key ne "ref"){ $text =~ s/\+/ /g; $text =~ s/%(..)/pack("c",hex($1))/ge; $text =~ s/%7e/~/ig; } $text =~ s/\r//g; $text =~ s/\n//g; $text =~ s//>/g; $text =~ s/&/&/g; $text =~ s/"/"/g; $IN{$key}=$text; } &main; exit; #****************************************************************************** sub main{ my ($ip,$host,$ua,$accept); my ($user_lang,$user_tz,$user_scr,$user_cd,$user_os,$user_bs); my ($a1,$a2,$a3,@top_acs,@temp1,@temp2); my ($visit_time,$last_visit); $ip=$ENV{'REMOTE_ADDR'}; $host = gethostbyaddr(pack("C4", split(/\./, $ip)), 2); $host = $ENV{'REMOTE_HOST'} if $host eq '' || $host eq $ip; $host = $ip if $host eq ''; $ua=$ENV{'HTTP_USER_AGENT'}; $accept = $ENV{'HTTP_ACCEPT'}; $user_bs_type = 0; #訪問回数 for $a3 (split(/; */, $ENV{'HTTP_COOKIE'})) { ($a1,$a2) = split(/=/, $a3); if ($a1 eq 'aad'){ ($visit_time,$last_visit) = split(/_/,$a2); last; } } $visit_time = 0 if $visit_time eq ''; if (($last_visit eq '') || ($ct_double < 1) || ($last_visit + $ct_double*3600 < time())){ $visit_time++; print "Set-Cookie:aad=".$visit_time."_".time()."; expires=Thu, 1-Jan-2030 00:00:00 GMT;\n"; #リファラーチェック if ($IN{'ref'} !~ /^http:/){ $IN{'ref'} = ''; } foreach(split(/\n/,$set_data3)){ if ($IN{'ref'} =~ /$_/i){$IN{'ref'} = "";last;} } #解像度 if (($IN{'wh'} !~ /[^\d]/) && ($IN{'ww'} !~ /[^\d]/) && ($IN{'wh'} ne "") && ($IN{'ww'} ne "") && ($IN{'wh'} > 0) && ($IN{'ww'} > 0)){ $user_scr = $IN{'ww'}.' x '.$IN{'wh'}; } #発色数 if ($IN{'cd'} !~ /[^\d]/){ $user_cd = $IN{'cd'}; $user_cd = 99 if $cd > 99; }else{ $user_cd = ''; } #言語環境 $user_lang = lc((split(/,/,$ENV{'HTTP_ACCEPT_LANGUAGE'},2))[0]); #アクセス地域 if ($IN{'tz'} =~ /[^0-9-]/){ $user_tz = ''; }else{ $user_tz = -1 * $IN{'tz'};$user_tz++;$user_tz--; } #OS解析 if ($ua =~ /Windows 3\.\d+/i){$user_os='Windows 3.x';} elsif (($ua =~ /Win9x 4\.90/i) || ($ua =~ /Win 9x 4\.90/i)){$user_os="Windows ME";} elsif (($ua =~ /Windows 95/i) || ($ua =~ /Win95/i) || ($ua =~ /Win32/i)){$user_os='Windows 95';} elsif (($ua =~ /Windows 98/i) || ($ua =~ /Win98/i)){$user_os='Windows 98';} elsif (($ua =~ /Windows NT ?5/i) || ($ua =~ /WinNT ?5/i) || ($ua =~ /Windows ?2000/i) || ($ua =~ /Win ?2000/i)){$user_os='Windows 2000';} elsif (($ua =~ /Windows CE/i) || ($ua =~ /WinCE/i)){$user_os='Windows CE';} elsif (($ua =~ /Windows NT/i) || ($ua =~ /WinNT/i)){$user_os='Windows NT';} elsif (($ua =~ /Windows XP/i) || ($ua =~ /WinXP/i)){$user_os='Windows XP';} elsif ($ua =~ /Mac_PowerPC/i){$user_os='Mac PowerPC';} elsif ($ua =~ /Macintosh/i){$user_os='Macintosh';} elsif ($ua =~ /X11/i){$user_os='X11';} elsif ($ua =~ /AIX/i){$user_os='AIX';} elsif ($ua =~ /WebTV/i){$user_os='WebTV';} elsif ($ua =~ /passport/i){$user_os='DreamCast';} elsif ($ua =~ /SEGASATURN/i){$user_os='SEGASATURN';} elsif ($ua =~ /Amiga-AWeb/){$user_bs='AmigaOS';} elsif ($ua =~ /Vine/i){$user_os='Vine Linux';} elsif ($ua =~ /Debian/i){$user_os='Debian GNU/Linux';} elsif ($ua =~ /Omoikane/i){$user_os='Omoikane GNU/Linux';} elsif ($ua =~ /OpenLinux/i){$user_os='OpenLinux';} elsif ($ua =~ /Plamo/i){$user_os='Plamo Linux';} elsif ($ua =~ /Red ?Hat/i){$user_os='Red Hat Linux';} elsif ($ua =~ /Turbo ?Linux/i){$user_os='Turbolinux';} elsif ($ua =~ /Slackware/i){$user_os='Slackware';} elsif ($ua =~ /HOLON/i){$user_os='HORON Linux';} elsif ($ua =~ /Kondara/i){$user_os='Kondara MNU/Linux';} elsif ($ua =~ /Laser ?5/i){$user_os='LASER5/Linux';} elsif ($ua =~ /Mandrake/i){$user_os='Linux Mandrake';} elsif ($ua =~ /Linux ?MLD/i){$user_os='Linux MLD';} elsif ($ua =~ /LiveLinux/i){$user_os='LiveLinux';} elsif ($ua =~ /Linux/i){$user_os='Linux';} elsif ($ua =~ /OSF1/i){$user_os='Digital UNIX';} elsif ($ua =~ /BeOS/i){$user_os='BeOS';} elsif ($ua =~ /OS\/2/i){$user_os='OS/2';} elsif ($ua =~ /SunOS/i){$user_os='SunOS';} elsif ($ua =~ /HP-UX/i){$user_os='HP-UX';} elsif ($ua =~ /HI-UX/i){$user_os='HI-UX';} elsif ($ua =~ /FreeBSD/i){$user_os='FreeBSD';} elsif ($ua =~ /NetBSD/i){$user_os='NetBSD';} elsif ($ua =~ /OpenBSD/i){$user_os='OpenBSD';} elsif ($ua =~ /BSD/i){$user_os='BSD';} elsif ($ua =~ /AIX/i){$user_os='AIX';} elsif ($ua =~ /IRIX/i){$user_os='IRIX';} elsif ($ua =~ /UNIX/i){$user_os='UNIX';} elsif ($ua =~ /^DoCoMo/i){$user_os='i-mode';} elsif ($ua =~ /^UP\.browser/i){$user_os='EZweb';} elsif ($ua =~ /^J-PHONE/i){$user_os='J-Skyweb';} elsif ($ua =~ /^ASTEL/i){$user_os='ドットi';} elsif ($ua =~ /^PDXGW/i){$user_os='PDX/H"/feelH"';} elsif ($ua =~ /sharp wd browser/i){$user_os = '書院';} elsif ($ua =~ /sharp pda browser/i){$user_os = 'Zaurus';} elsif (($ua =~ /AVE-Front/) && ($ua =~ /Product=([^;]*);/)){$user_os = (split(/_/,$1,2))[0];} else{$user_os='';} #ブラウザ解析 #NN解析を始めに行う。 $user_bs = "";$user_bs_type = 0; if ($ua =~ /Netscape6/){$user_bs = 'Netscape Navigator 6.0';$user_bs_type=0;} if ($ua =~ /Gecko/i){ } if ($ua =~ /Netscape6\/([\w+])/){$user_bs = "Netscape Navigator $1";$user_bs_type=0;} elsif ($ua =~ /Gecko/i){$user_bs = "Netscape Navigator 6.0";$user_bs_type = 0;} elsif ($ua =~ /ANONYMIZER/i){$user_bs='THE ANONYMIZER';$user_bs_type=9;} elsif ($ua =~ /Getweb!/i){$user_bs = 'Getweb!';$user_bs_type = 1;} elsif ($ua =~ /NetCaptor/i){$user_bs = 'NetCaptor';$user_bs_type = 0;} elsif ($ua =~ /Cuam/i){$user_bs = 'Cuam';$user_bs_type = 0;} elsif ($ua =~ /Iria/i){$user_bs = 'Iria';$user_bs_type = 9;} elsif ($ua =~ /ReGet/i){$user_bs = 'ReGet';$user_bs_type = 9;} elsif ($ua =~ /FlashGet/i){$user_bs = 'FlashGet';$user_bs_type = 9;} elsif ($ua =~ /Passport/i){$user_bs='Dream Passport';$user_bs_type=0;} elsif ($ua =~ /SEGASATURN/i){$user_bs='SEGASATURN';$user_bs_type=0;} elsif ($ua =~ /PlanetWeb/i){$user_bs = 'PlanetWeb';$user_bs_type=0;} elsif ($ua =~ /Amaya/i){$user_bs='Amaya';$user_bs_type=0;} elsif ($ua =~ /Amiga-AWeb/i){$user_bs='Amiga-AWeb';$user_bs_type=0;} elsif ($ua =~ /ANT Fresco/i){$user_bs = 'ANT Fresco';$user_bs_type=0;} elsif ($ua =~ /Aplix/i){$user_bs = 'Aplix';$user_bs_type=0;} elsif ($ua =~ /Arena/i){$user_bs = 'Arena';$user_bs_type=0;} elsif ($ua =~ /xChaos_Arachne/i){$user_bs = 'Arachne';$user_bs_type=0;} elsif ($ua =~ /AvantGo/i){$user_bs='AvantGo';$user_bs_type=0;} elsif ($ua =~ /AVE-Front/i){$user_bs='AVE-Front';$user_bs_type=0;} elsif ($ua =~ /BBB/i){$user_bs = 'BBB';$user_bs_type=0;} elsif ($ua =~ /Cab/){$user_bs = 'Cab';$user_bs_type=0;} elsif ($ua =~ /Chimera/i){$user_bs = 'Chimera';$user_bs_type=0;} elsif ($ua =~ /CyberDog/i){$user_bs='CyberDog';$user_bs_type=0;} elsif ($ua =~ /Spyglass/i){$user_bs='Device Mosaic';$user_bs_type=0;} elsif ($ua =~ /EasyRider/i){$user_bs = 'EasyRider';} elsif ($ua =~ /Emacs/i){$user_bs='Emacs';$user_bs_type=0;} elsif ($ua =~ /Enhanced_Mosaic/i){$user_bs = 'Enhanced Mosaic';$user_bs_type=0;} elsif ($ua =~ /Flashnavi/){$user_bs='Flashnavi';$user_bs_type=0;} elsif ($ua =~ /FrontPage/i){$user_bs='FrontPage';$user_bs_type=0;} elsif ($ua =~ /Foliage.?iBrowser/i){$user_bs='Foliage iBrowser';$user_bs_type=0;} elsif ($ua =~ /gzilla/i){$user_bs = 'Gzilla';$user_bs_type=0;} elsif (($ua =~ /HotJava/i) || (($ua =~ /Mozilla\/3.0/i) && ($accept =~ /q=\.2\,/))){$user_bs = 'HotJava';} elsif ($ua =~ /IBrowse/i){$user_bs='IBrowse';$user_bs_type=0;} elsif ($ua =~ /iCab/i){$user_bs='iCab';$user_bs_type=0;} elsif ($ua =~ /IWENG/i){$user_bs='IWENG';$user_bs_type=0;} elsif ($ua =~ /JustView/i){$user_bs='JustView';$user_bs_type=0;} elsif ($ua =~ /Lite/i){$user_bs='Lite';$user_bs_type=0;} elsif ($ua =~ /Lynx/i){$user_bs = 'Lynx';$user_bs_type=0;} elsif ($ua =~ /Links/i){$user_bs = 'Links';$user_bs_type=0;} elsif ($ua =~ /NCSA_?Mosaic/i){$user_bs='Pocket Internet Explorer';$user_bs_type=0;} elsif ($ua =~ /MSPIE/i){$user_bs='Pocket Internet Explorer';$user_bs_type=0;} elsif ($ua =~ /MSIA/i){$user_bs = 'Microsoft Internet Assistant';$user_bs_type=0;} elsif ($ua =~ /Navigate_with_an_Accent/i){$user_bs = 'Navigate width an Accent';$user_bs_type=0;} elsif ($ua =~ /NaviPress/i){$user_bs = 'NaviPress';$user_bs_type=0;} elsif ($ua =~ /NetPositive/i){$user_bs = 'NetPositive';$user_bs_type=0;} elsif ($ua =~ /Websurfer/i){$user_bs = 'WebSurfer';$user_bs_type=0;} elsif ($ua =~ /NETSGO/i){$user_bs = 'NETSGO';$user_bs_type=0;} elsif ($ua =~ /OmniWeb/i){$user_bs='OmniWeb';$user_bs_type=0;} elsif ($ua =~ /Opera/i){$user_bs='Opera';$user_bs_type=0;} elsif ($ua =~ /pwWebSpeak/i){$user_bs = 'pwWebSpeak';$user_bs_type=0;} elsif ($ua =~ /Sax Webster/i){$user_bs = 'Sax Webster';$user_bs_type=0;} elsif ($ua =~ /Sextant/i){$user_bs = 'Sextant';$user_bs_type=0;} elsif ($ua =~ /StarOffice/i){$user_bs = 'StarOffice';$user_bs_type=0;} elsif ($ua =~ /URL_Captor/i){$user_bs = 'URLキャプター';$user_bs_type=0;} elsif ($ua =~ /QNX/i){$user_bs = 'QNX Voyager';$user_bs_type=0;} elsif ($ua =~ /w3m/i){$user_bs = 'w3m';$user_bs_type=0;} elsif ($ua =~ /WebBoy/i){$user_bs = 'WebBoy';$user_bs_type=0;} elsif ($ua =~ /WebExplorer/i){$user_bs = 'WebExplorer';$user_bs_type=0;} elsif ($ua =~ /WebTV/i){$user_bs='WebTV';$user_bs_type=0;} elsif ($ua =~ /Wildcat/i){$user_bs = 'Wildcat!';$user_bs_type=0;} elsif (($ua =~ /World TALK/i) || ($ua =~ /WorldTALK/i)){$user_bs = 'WorldTALK';$user_bs_type=0;} elsif ($ua =~ /Plala-Browser/i){$user_bs = 'ぷららブラウザ';$user_bs_type=0;} elsif ($ua =~ /MSIE (\d+\.\d+)/i){ if ($ua =~ /MSN/){ $user_bs = "MSN Explorer"; }else{ $user_bs = "Internet Explorer $1";$user_bs_type=0; } } elsif ($ua =~ /^DoCoMo/i){$user_bs='i-mode';$user_bs_type=0;} elsif ($ua =~ /^UP\.browser/i){$user_bs='EZweb';$user_bs_type=0;} elsif ($ua =~ /^J-PHONE/i){$user_bs='J-Skyweb';$user_bs_type=0;} elsif ($ua =~ /^ASTEL/i){$user_bs='ドットi';$user_bs_type=0;} elsif ($ua =~ /^PDXGW/i){$user_bs='PDX/H"/feelH"';$user_bs_type=0;} elsif ($ua =~ /ArchitextSpider/i){$user_bs='ArchitextSpider';$user_bs_type=1;} elsif ($ua =~ /BullsEye/i){$user_bs='Bullseye';$user_bs_type=1;} elsif ($ua =~ /Commerobo/i){$user_bs='Commerobo';$user_bs_type=1;} elsif ($ua =~ /Child Research Net Spider/i){$user_bs='Child Research Net Spider';$user_bs_type=1;} elsif ($ua =~ /fly\/(\d+\.\d+) libwww/i){$user_bs='LiveLink Spider';$user_bs_type=1;} elsif (($ua=~ /Gensho Checker/i) || ($ua=~ /Down Site Checker/i)){$user_bs = 'Gensho Checked';$user_bs_type=1;} elsif ($ua =~ /Googlebot/i){$user_bs='Googlebot';$user_bs_type=1;} elsif ($ua =~ /Hatch Meta Checker/i){$user_bs='Hatch Meta Checker';$user_bs_type=1;} elsif ($ua =~ /InfoNavirobot/i){$user_bs='InfoNavirobot';$user_bs_type=1;} elsif ($ua =~ /InfoSeek Sidewinder/i){$user_bs='InfoSeek Sidewinder';$user_bs_type=1;} elsif ($ua =~ /iYappo/i){$user_bs='iYappo';$user_bs_type=1;} elsif ($ua =~ /Jerky/i){$user_bs='Jerky';$user_bs_type=1;} elsif ($ua =~ /Lycos_Spider/i){$user_bs='Lycos Spider';$user_bs_type=1;} elsif ($ua =~ /yahoo-fetch/i){$user_bs='yahoo-fetch';$user_bs_type=1;} elsif ($ua =~ /Asahina-Antenna/i){$user_bs='朝日奈アンテナ';$user_bs_type=1;} elsif ($ua =~ /WWWC/i){$user_bs='WWWC';$user_bs_type=1;} elsif ($ua =~ /httpdown/i){$user_bs='HTTPDown';$user_bs_type=1;} elsif ($ua =~ /PageDown/i){$user_bs='PageDown';$user_bs_type=1;} elsif ($ua =~ /Internet ?Ninja/i){$user_bs='Internet Ninja';$user_bs_type=1;} elsif ($ua =~ /Pockey/i){$user_bs='GetHTMLW';$user_bs_type=1;} elsif ($ua =~ /Wget/i){$user_bs='Wget';$user_bs_type=1;} elsif ($ua =~ /Inetdown/i){$user_bs='Inetdown';$user_bs_type=1;} elsif ($ua =~ /MSProxy/i){$user_bs='Mictosoft Proxy Server';$user_bs_type=9;} elsif ($ua =~ /CERN/i){$user_bs='CERN';$user_bs_type=9;} elsif ($ua =~ /BlackJumboDog/i){$user_bs='BlackJumboDog';$user_bs_type=9;} elsif ($ua =~ /DidYouSeeAnElephant/i){$user_bs='COTSE Anonymouse Web';$user_bs_type=9;} elsif ($ua =~ /Another_HTML-lint/i){$user_bs = 'Another_HTML-lint';$user_bs_type=9;} elsif ($ua =~ /BMchecker/i){$user_bs = 'BMchecker';$user_bs_type=9;} elsif ($ua =~ /Bookmark Mate/i){$user_bs = 'Bookmark Mate';$user_bs_type=9;} elsif ($ua =~ /BrowserCrasherChecker/i){$user_bs = 'BrowserCrasherChecker';$user_bs_type = 9;} elsif ($ua =~ /Hutech/i){$user_bs = 'Hutech';$user_bs_type = 9;} elsif ($ua =~ /Ginga/i){$user_bs='Ginga';$user_bs_type=9;} elsif ($ua =~ /Shodouka/i){$user_bs='Shodouka';$user_bs_type=9;} elsif ($ua =~ /URL-Battle/i){$user_bs='URL-Battle';$user_bs_type=9;} elsif ($ua =~ /^Mozilla\/(\d+\.\d+)/){$user_bs = "Netscape Navigator $1";$user_bs_type=0;} else{$user_bs='';$user_bs_type=0;} @temp1 = gmtime($area_time+time()); $a1 = sprintf("%04d%02d%02d",$temp1[5]+1900,$temp1[4]+1,$temp1[3]); if (!-e "$dir_log/$a1.dat"){ #日付変更 @temp1 = gmtime($area_time+time()-$set_data1[0]*86400); $a2 = sprintf("%04d%02d%02d",$temp1[5]+1900,$temp1[4]+1,$temp1[3]); unlink("$dir_log/$a2.dat") if -e "$dir_log/$a2.dat"; open(IO,"+<$dir_acs/top.dat"); eval{flock(IO,2)}; @top_acs = split(/<>/,);pop(@top_acs); @temp1 = split(/<>/,);pop(@temp1); @temp2 = split(/<>/,);pop(@temp2); $top_acs[0]++; $top_acs[2]=$top_acs[1]; $top_acs[1]=1; $a2 = int(time()/3600)-int($top_acs[3]/3600); if ($a2 >= $set_data1[1]){@temp1 = ();} elsif($a2 >= 1){for(1..$a2){unshift(@temp1,0);}} $temp1[0]++; $a2 = int((time()+$area_time)/86400)-int(($top_acs[3]+$area_time)/86400); if ($a2 >= $set_data1[2]){@temp2 = ();} elsif($a2 >= 1){for(1..$a2){unshift(@temp2,0);}} $temp2[0]++; truncate(IO,0); seek(IO,0,0); print IO "$top_acs[0]<>$top_acs[1]<>$top_acs[2]<>".time()."<>\n"; for(0..$set_data1[1]){print IO $temp1[$_]."<>";}print IO "\n"; for(0..$set_data1[2]){print IO $temp2[$_]."<>";}print IO "\n"; close(IO); $temp1[0] = 1; open(OUT,">$dir_log/$a1.dat"); eval{flock(OUT,2)}; }else{ open(IO,"+<$dir_acs/top.dat"); eval{flock(IO,2)}; @top_acs = split(/<>/,);pop(@top_acs); @temp1 = split(/<>/,);pop(@temp1); @temp2 = split(/<>/,);pop(@temp2); $top_acs[0]++;$top_acs[1]++; $a2 = int(time()/3600)-int($top_acs[3]/3600); if ($a2 >= $set_data1[1]){@temp1 = ();} elsif($a2 >= 1){for(1..$a2){unshift(@temp1,0);}} $temp1[0]++; $temp2[0]++; truncate(IO,0); seek(IO,0,0); print IO "$top_acs[0]<>$top_acs[1]<>$top_acs[2]<>".time()."<>\n"; for(0..$set_data1[1]-1){print IO $temp1[$_]."<>";}print IO "\n"; for(0..$set_data1[2]-1){print IO $temp2[$_]."<>";}print IO "\n"; close(IO); $temp1[0] = 0; open(OUT,">>$dir_log/$a1.dat"); eval{flock(OUT,2)}; } print OUT time()."<>$ip<>$host<>$ua<>$user_os<>$user_bs_type<>$user_bs<>$IN{'ref'}<>$user_scr<>$user_cd<>$user_lang<>$user_tz<>$visit_time<>\n"; close(OUT); chmod(0666,"$dir_log/$a1.dat") if $temp1[0]; }else{ open(IN,"$dir_acs/top.dat"); eval{flock(IN,1)}; @top_acs = split(/<>/,); close(IN); } if($top_ct_indi == 0){ print "Content-type:image/gif\n\n"; binmode(STDOUT); open(IN,$top_ct_setimg); binmode(IN); while(){print;} close(IN); }else{ @temp1=(); $top_ct_fig[0]=0 if $top_ct_fig[0] eq ''; $a1 = sprintf("%0".$top_ct_fig[0]."d",$top_acs[0]); foreach(split(//,sprintf("%0".$top_ct_fig[0]."d",$top_acs[0]))){ push(@temp1,$top_ct_img[0]."/$_.gif"); } require $lib_gifcat; print "Content-type: image/gif\n\n"; binmode(STDOUT); print &gifcat::gifcat(@temp1); } exit; } #******************************************************************************